#include<bits/stdc++.h>
using namespace std;
long long a[200005],dp[200005][2],k[200005];
int b[1000005],c[1000005];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int t,n;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(k,0,sizeof(k));
		for(int i=1;i<=n;i++){
			scanf("%lld",&a[i]);
			dp[i][0]=dp[i][1]=0;
			if(a[i]==a[i-1]) k[i]=a[i-1];
			k[i]+=k[i-1];
			c[i]=b[a[i]];
			b[a[i]]=i;
		}
		for(int i=1;i<=n;i++){
			dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
			if(a[i]==a[i-1]) dp[i][0]+=a[i];
			dp[i][1]=max(max(dp[i-1][0],dp[i-1][1]),dp[c[i]+1][1]+k[i]-k[c[i]+1]+a[c[i]]);
		}
		printf("%lld\n",max(dp[n][0],dp[n][1]));
	}
	return 0;	
}
